package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.domain.ProductAttributeCategory;
import com.itheima.manager.PmsProductAttributeCategoryManager;
import com.itheima.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class PmsProductAttributeCategoryController {
    @Autowired
    PmsProductAttributeCategoryManager pmsProductAttributeCategoryManager;

    //分页获取所有商品属性分类
    @GetMapping("/productAttribute/category/list")
    public R<PageBeanVo> findByPage(@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                                    @RequestParam(value="pageSize",defaultValue = "5")Integer pageSize){
        return pmsProductAttributeCategoryManager.findByPage(pageNum,pageSize);
    }

    //添加商品属性分类
    @PostMapping("/productAttribute/category/create")
    public R<String> saveAttributeCategory(@RequestBody ProductAttributeCategory productAttributeCategory){
        return pmsProductAttributeCategoryManager.saveAttributeCategory(productAttributeCategory);
    }

    //删除单个商品属性分类
    @GetMapping("/productAttribute/category/delete/{id}")
    public R<String> deleteAttributeCategory(@PathVariable Long id){
        return pmsProductAttributeCategoryManager.deleteAttributeCategory(id);
    }

    //获取所有商品属性分类及其下属性
    @GetMapping("/productAttribute/category/list/withAttr")
    public R<List<Map<String,Object>>> findAttrCateAndAttr(){
        return pmsProductAttributeCategoryManager.findAttrCateAndAttr();
    }

    //修改商品属性分类
    @PostMapping("/productAttribute/category/update/{id}")
    public R<String> updateAttrCate(@PathVariable Long id,@RequestBody ProductAttributeCategory productAttributeCategory){
        return pmsProductAttributeCategoryManager.updateAttrCate(productAttributeCategory);
    }

    //获取单个商品属性分类信息
    @GetMapping("/productAttribute/category/{id}")
    public R<ProductAttributeCategory> findById(@PathVariable Long id){
        return pmsProductAttributeCategoryManager.findById(id);
    }
}
